package com.nc.mem.serial.graph.boot.impl;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.GregorianCalendar;
import java.util.IdentityHashMap;
import java.util.Map.Entry;

import com.nc.mem.serial.Serializer;
import com.nc.mem.serial.graph.boot.ProvisionService;
import com.nc.mem.serial.graph.boot.RegistrationListener;
import com.nc.mem.serial.graph.common.CalendarSerializer;
import com.nc.mem.serial.graph.common.CompatibleSerializer;
import com.nc.mem.serial.graph.common.EnumSerializer;
import com.nc.mem.serial.graph.common.IntegerSerializer;
import com.nc.mem.serial.graph.common.LongSerializer;
import com.nc.mem.serial.graph.common.StringSerializer;
import com.nc.mem.serial.graph.container.CollectionRegistry;
import com.nc.mem.serial.graph.cust.FixedKeyValMapSerializer;
import com.nc.mem.serial.graph.cust.FixedTypeCollectionSerializer;

public final class BasicProvisionServiceImpl implements ProvisionService {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public Iterable<Entry<Serializer, Iterable<Class<?>>>> installableAbstractions() {
		return (Iterable) Collections.singletonMap(EnumSerializer.INSTANCE, Collections.singleton(Enum.class)).entrySet();
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public Iterable<Class<?>> installableClosures() {
		return (Iterable) Collections.singleton(Comparator.class);
	}

	@Override
	public Iterable<Entry<Integer, Class<?>>> installableMappings() {
		return null;
	}

	@Override
	public Iterable<Entry<Class<?>, Class<?>>> installableReplacements() {
		return null;
	}

	@Override
	public Iterable<Entry<Class<?>, Serializer>> installableSerializers() {
		final IdentityHashMap<Class<?>, Serializer> map = new IdentityHashMap<Class<?>, Serializer>(4);

		map.put(Object.class, CompatibleSerializer.INSTANCE);
		map.put(String.class, StringSerializer.INSTANCE);
		map.put(Calendar.class, CalendarSerializer.INSTANCE);
		map.put(GregorianCalendar.class, CalendarSerializer.INSTANCE);
		map.put(Integer.class, new IntegerSerializer());
		map.put(Long.class, new LongSerializer());

		return map.entrySet();
	}

	@Override
	public Iterable<RegistrationListener> listeners() {
		return Arrays.asList(CollectionRegistry.INSTANCE, FixedTypeCollectionSerializer.INSTANCE, FixedKeyValMapSerializer.INSTANCE);
	}

}
